package com.chub.study.modules.service.impl;

import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chub.study.modules.dto.CityDto;
import com.chub.study.modules.entity.TCity;
import com.chub.study.modules.mapper.TCityMapper;
import com.chub.study.modules.service.TCityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.*;

/**
 * <p>
 * 行政区划表 服务实现类
 * </p>
 *
 * @author chub
 * @since 2021-08-26
 */
@Service
public class TCityServiceImpl extends ServiceImpl<TCityMapper, TCity> implements TCityService {

    @Autowired
    private TCityMapper cityMapper;

    @Override
    public List<TCity> queryCityByParentId(String id) {

        if (StrUtil.isBlank(id)) {
            return null;
        }

        Map<String, Object> map = new HashMap<>();
        map.put("PARENT_ID", id);


        List<TCity> cityList = cityMapper.selectByMap(map);
        if (IterUtil.isEmpty(cityList)) {
            return null;
        }
        for (TCity city: cityList) {
            city.setUptTime(LocalDateTime.now());
        }

        return cityList;
    }

    @Override
    public List<TCity> queryCityList(Map<String, Object> map) {

        if (map == null) {
            return null;
        }

        return cityMapper.selectByMap(map);
    }

    @Override
    public List<TCity> queryCityInfo(String id) {
        return cityMapper.queryCityInfo(id);
    }

    @Override
    public List<TCity> queryCityListByMap(Map map) {

        return cityMapper.queryCityListByMap(map);
    }

    @Override
    public List<TCity> queryCityListByMapRespBeanList(Map map) {

        return cityMapper.queryCityListByMap(map);
    }

    @Override
    public List<TCity> queryCityListByBean(TCity city) {

        return cityMapper.queryCityListByBean(city);
    }

    @Override
    public List<String> queryCityInfoRespArrString(String id) {

        return cityMapper.queryCityInfoRespArrString(id);
    }

    @Override
    public Map<Integer, TCity> queryCityInfoRespMap(String id) {
        return cityMapper.queryCityInfoRespMap(id);
    }

    @Override
    public List<Map<String, Object>> queryCityInfoRespMap1(String id) {
        return cityMapper.queryCityInfoRespMap1(id);
    }

    @Override
    public List<Arrays> queryCityInfoRespArray(String id) {
        return cityMapper.queryCityInfoRespArray(id);
    }

    @Override

    public Map<Integer, TCity> queryCityInfoAsMap(String id) {
        return cityMapper.queryCityInfoAsMap(id);
    }

    @Override
    public List<TCity> queryCityInfoByList(List<String> list) {
        return cityMapper.queryCityInfoByList(list);
    }

    @Override
    public List<TCity> queryCityInfoByArray(String[] cityIds) {
        return cityMapper.queryCityInfoByArray(cityIds);
    }

    @Override
    public List<TCity> queryCityInfoByMapKeyValue(Map map) {
        return cityMapper.queryCityInfoByMapKeyValue(map);
    }

    @Override
    public List<TCity> queryCityInfoByMapKey(Map map) {
        return cityMapper.queryCityInfoByMapKey(map);
    }

    @Override
    public List<TCity> queryCityInfoByMapValue(Map map) {
        return cityMapper.queryCityInfoByMapValue(map);
    }

    @Override
    public List<TCity> queryCityInfoByUptTime(TCity tCity) {
        return cityMapper.queryCityInfoByUptTime(tCity);
    }

    @Override
    public IPage<Map<String, Object>> queryByPage1(IPage<Map<String, Object>> page, Map<String, Object> forQuery) {
        return cityMapper.queryByPage1(page, forQuery);
    }

    @Override
    public CityDto saveCityList(CityDto dto) {
        String id = "";
        // dto.getCityList().stream().peek(item->{
        //     item.setId(1);
        //     item.setCityName("曹县");
        // }).forEach(cityMapper::insert);

        // dto.getCityList().stream().peek(item->{
        //     item.setId(1);
        //     item.setCityName("曹县");
        // }).forEach(item1->{
        //     cityMapper.insert(item1);
        //     item1.get
        // });

        return null;
    }
    // 加工数据成树形结构，
    // public List<Tree<Long>> listWithTree() {
    //     List<TCity> entities = baseMapper.selectList(wrapper:null);
    //     if(!CollectionUtil.isEmpty(entities)) {
    //         List<TreeNode<Long>> list = entities
    //                 .stream()
    //                 .map(CategoryServiceImpl::getLongTreeNode)
    //                 .collect(Collectors.toList());
    //         return TreeUtil.build(list, parentld);
    //     }
    // }
    //
    // private static TreeNode<Long> getLongTreeNode(TCity item){
    //     TreeNode<Long> treeNode = new TreeNode<>();
    //
    //     treeNode.setId(item.getCatId());
    //     treeNode.setParentId(item.getParentcid());
    //     treeNode.setName(item.getName()),
    //             treeNode.setWeight(item.getSort());
    //     Map<String, Object> extra = new HashMap<>();
    //     extra.put("showStatus",item.getShowStatus());
    //     extra.put("catLevel", item.getCatLevel());
    //     extra.put("icon",item.getIcon());
    //     extra.put("productUnit",item.getProductUnit());
    //     extra.put("productCount",item.getProductCount());
    //     treeNode.setExtra(extra);
    //     return treeNode;
    // }






}
